package com.example.neusoft.yuejian_12.Activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.neusoft.yuejian_12.JavaBean.User;
import com.example.neusoft.yuejian_12.Listener.UserListener;
import com.example.neusoft.yuejian_12.Model.UserModel;
import com.example.neusoft.yuejian_12.R;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class RegisterActivity extends AppCompatActivity implements View.OnClickListener, UserListener {
    private Button button_reg, button_cancle;
    private EditText et_pass;
    private EditText et_tele;
    private EditText et_name;
    String name;
    String phone;
    String pwd;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        initViews();
    }

    public void initViews(){
        button_reg=(Button)findViewById(R.id.regbtn_reg);
        button_cancle=(Button)findViewById(R.id.regbtn_back);
        et_pass=(EditText)findViewById(R.id.regpassword);
        et_tele=(EditText)findViewById(R.id.regtelephone);
        et_name=(EditText)findViewById(R.id.regusername);
        button_reg.setOnClickListener(this);
        button_cancle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(RegisterActivity.this,LoginActivity.class);
                startActivityForResult(intent,1);
                intent.getExtras();
            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.regbtn_reg:
                name = et_name.getText().toString();
                pwd = et_pass.getText().toString();
                phone = et_tele.getText().toString();
                UserModel usermodel = new UserModel();
                usermodel.Register(name,pwd, phone, this);
                break;
        }
    }

    //这个方法是在Model中调用的
    @Override
    public void onResponse(User userBean) {
        Toast.makeText(this, "注册成功!", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onFail(String msg) {
        Toast.makeText(this, "" + msg, Toast.LENGTH_SHORT).show();
    }
}